<!-- $Id: case.html 149 2009-08-11 13:31:31Z doug.hellmann $ -->
{% extends "base.html" %}
{% load thumbnail %}

{% block pagetitle %} | Case {{case.hearing_date.year}}/{{case.num}} {% endblock %}

{% block breadcrumbs %}
  <a href="{% url docket.arrest.decade_list %}">Browse</a>
  | <a href="{% url docket.arrest.decade decade %}">{{decade}}</a>
  | <a href="{% url docket.arrest.month case.hearing_date.year,case.hearing_date.month %}">{{case.hearing_date|date:"Y/m"}}</a>
{% endblock %}

{% block navigation %} 
    <div><a href="{% url docket.arrest.month case.hearing_date.year,1 %}">{{case.hearing_date|date:"Y"}}</a></div>
  {% for month in month_list %}
	<div><a href="{% url docket.arrest.month month.year,month.month %}">{{ month|date:"M" }}</a></div>
  {% endfor %}

  <hr />
	
  <div><a href="">Page {{case.page}} of volume
  {{case.book.volume}} from {{case.year}}</a></div>

{% endblock %}

{% block content %}
  <h2>Case {{case.hearing_date.year}}/{{case.num}}</h2>

  <div class="case">

	<fieldset>
	<legend>Defendant</legend>
	<table>
	  <tr><th>Name</th><td><a href="{% url docket.views.search %}?first_name={{defendant.first_name}}&last_name={{defendant.last_name}}">{{ defendant.name }}</a></td></tr>
	  {% if defendant.gender %}<tr><th>Gender</th><td>{{ defendant.get_gender_display }}</td></tr>{% endif %}
	  {% if defendant.race %}<tr><th>Race</th><td>{{ defendant.race }}</td></tr>{% endif %}
	  {% if defendant.notes %}<tr><th>Notes</th><td>{{ defendant.notes|safe }}</td></tr>{% endif %}
	</table>
	</fieldset>

	<fieldset>
	<legend>Arrest Details</legend>
	<table>
	  <tr><th>Date</th><td>{{ case.arrest_date|date:"d M Y" }}</td></tr>
	  <tr><th>Location</th><td>{{ case.arrest_location }}</td></tr>

	  <tr>
		<th>Violation{{ case.violation_set.all|pluralize }}</th>
		<td>
		  {% for violation in case.violation_set.all %}
		  <div>{% if violation.code.code %}<span class="violation_code">{{ violation.code.code }}</span>: {{violation.code.summary}} {% endif %}{% if violation.notes %} {{violation.notes}}{% endif %}</div>
		  {% endfor %}
		</td>
	  </tr>
	  
	</table>
	</fieldset>

	<fieldset>
	<legend>Hearing Details</legend>
	<table>
	  <tr><th>Date</th><td>{{ case.hearing_date|date:"d M Y" }}</td></tr>
	  <tr><th>Plea</th><td>{{ case.get_plea_display }}</td></tr>
	  <tr><th>Outcome</th><td>{{ case.get_outcome_display }}</td></tr>
	</table>
	</fieldset>

	<fieldset>
	<legend>Sentence</legend>

	<div class="sentence">
	<b>Rendered</b>
	{% if case.sentence_rendered %}
		<br/>
		{% for sentence in case.sentence_rendered.options %}
			{% if sentence.amount_is_money %}
				$ {{sentence.amount|floatformat:"2"}}
			{% else %}
				{{sentence.amount|floatformat:"-2"}}
			{% endif %}
	  		{{sentence.get_amount_kind_display}}{% if sentence.note %} ({{sentence.note}}){% endif %}
	  		{% if forloop.last %}{% else %} <i>or</i> {% endif %}
		{% endfor %}
		{% if case.sentence_rendered.options %}<br/>{% endif %}
		{% for sentence in case.sentence_rendered.required %}
			{% if sentence.amount_is_money %}
				$ {{sentence.amount|floatformat:"2"}}
			{% else %}
				{{sentence.amount|floatformat:"-2"}}
			{% endif %}
	  		{{sentence.get_amount_kind_display}}{% if sentence.note %} ({{sentence.note}}){% endif %}
	  		{% if forloop.last %}{% else %} <i>and</i> {% endif %}
		{% endfor %}
	{% else %}
	Unknown
	{% endif %}
	</div>
	
	<div class="sentence">
	<b>Served</b>
		{% if case.sentence_served %}

	{% regroup case.sentence_served by date as grouped %}
	<ul>
	  {% for group in grouped %}
	  <li>{{group.grouper|date:"d M Y"}}
	  <ul>
		{% for sentence in group.list %}
		{% if sentence.amount %}
		<li>{% if sentence.amount_is_money %}$ {{sentence.amount|floatformat:"2"}}{% else %}{{sentence.amount|floatformat:"-2"}}{% endif %}
		    {{sentence.get_amount_kind_display}}{% if sentence.note %}, {{sentence.note}}{% endif %}</li>
		{% else %}
		<li>{% if sentence.note %}{{sentence.note}}{% else %}{{sentence.get_amount_kind_display}}{% endif %}</li>
		{% endif %}
		{% endfor %}
	  </ul>
	  </li>
	  {% endfor %}
	</ul>
	{% else %}
	Unknown
	{% endif %}
	</div>

	</fieldset>

	<fieldset>
	<legend>People Involved in the Case</legend>
	<table class="datalist">
	  <tr>
		<th>Name</th>
		<th>Role</th>
		<th>Details</th>
	  </tr>
	  {% for participant in participants %}
	  <tr>
		<td><a href="{% url docket.views.search %}?first_name={{participant.first_name}}&last_name={{participant.last_name}}">{{ participant.name }}</a></td>
		<td>{{ participant.role }}</td>
		<td>
	  {% if participant.race %}{{ participant.race }} {% endif %}
	  {% if participant.gender %}{{ participant.get_gender_display }} {% endif %}
	  {% if participant.notes %}({{ participant.notes }}){% endif %}
		</td>
	  </tr>
	  {% endfor %}
	</table>
	</fieldset>
	
{% if case.notes %}
	<fieldset>
	<legend>Notes</legend>
	  {{ case.notes|linebreaks }}
	</fieldset>
{% endif %}

{% if mediafiles %}
	<fieldset>
	<legend>Related Files</legend>
	  {% for mediafile in mediafiles %}
	  <h2><a href="{{mediafile.get_image_url}}">{{ mediafile.title }}</a></h2>
	  <p>({{mediafile.citation}})</p>
	  <img src="{{mediafile|thumbnail:"400x500"}}" alt="{{mediafile.title}} ({{mediafile.citation}})"
	    style="margin: 1em; border: 2px solid black;" />
	  {% endfor %}
	</fieldset>
{% endif %}

	
  </div>
{% endblock %}
